layui.config({
    base: "../../script/private/"
}).extend({
    cookieMod: "cookie"
});

layui.use(["jquery", "cookieMod", "form"], function() {
    var $ = layui.jquery;
    var form = layui.form();

    $("#lg_btninfo").on("click", function() {
        $(this).submit();
        var user_name = $('input[name="username"]').val();
        var user_pwd = $('input[name="password"]').val();

        //服务器验证（模拟）
        var isAdmin = user_name == "admin" && user_pwd == "123456";
        var isUserA = user_name == "userA" && user_pwd == "userA";
        var isMatched = isAdmin || isUserA;

        if (isMatched) {
            // 获取记住密码checkbox状态
            var remberChk = $("input[name='like[rember]']").prop("checked");
            if (remberChk) {
                $.setCookie("userName", user_name, 24);
                $.setCookie("password", user_pwd, 24);
                alert("登陆成功,欢迎你," + user_name + "!");
                self.location.replace("back_index.html");
            } else {
                var aa = $.delCookie("userName");
                var bb = $.delCookie("password");
                alert("登陆成功,欢迎你," + user_name + "!");
                self.location.replace("back_index.html");
            }

        } else {
            alert("用户名或密码错误，请重新输入！");
        }

    });


    var loadCook = function() {
        var cUser = $.getCookie("userName");
        var cPwd = $.getCookie("password");
        if ((cUser && cPwd)) {
            $('input[name="username"]').val(cUser);
            $('input[name="password"]').val(cPwd);
            $("#rember").iCheck('check');
        }
        return false;
    };

    $(document).ready(function() {
        form.render();
        loadCook();

    });




});